<body>
<div class="container-fluid">
<div class="row" style="margin-top: 10%; margin-bottom: 10%;">
    <div class="col-lg-4 col-xs-12"></div>
    <div class="col-lg-4 col-xs-12" style="border: 1px solid #F36F00">
        <div class="row" style="background-color: orange; font-weight: bolder; font-size: 20px; padding: 10px; color: white; text-align: center"><span style="padding: 20px">TÌM TÀI KHOẢN CỦA BẠN</span></div>
        <div class="row" style="margin: 5px;">
            <div class="col-lg-5 col-xs-12">
                <div class="row">
                    <span> Nhập địa chỉ email: </span>
                </div>
            </div>
            <div class="col-lg-7 col-xs-12">
                <div class="row">
                    <input style="width: 90%" type="text" class="form-control" id="txtReSendEmailFP" value="<?php echo $email ?>">
                </div>
            </div>
        </div>
        <div class="row" style="margin: 5px;">
            <div class="col-lg-5 col-xs-12">
                <div class="row">
                    <span> Nhập mã bảo mật: </span>
                </div>
            </div>
            <div class="col-lg-7 col-xs-12">
                <div class="row">
                    <input style="width: 90%; margin-bottom: 5px;" type="text" class="form-control" id="txtReSendCaptchaFP">
                </div>
                <div class="row">
                    <div class="content">
                        <span id="imgCaptcha"><?php echo $captcha ?></span>
                        <a href="#" id="btnChangeCaptcha" onclick="changeCaptcha();"><img src="<?php echo base_url() ?>assets/images/refresh.png" title="Đổi mã bảo mật"></a>
                    </div>
                </div>
            </div>
        </div>
        <div class="row" style="text-align: center; color: darkgreen; margin: 5px;" id="divReSendEmailFP"></div>
        <div class="row" style="margin: 20px; text-align: center">
            <span style="padding: 10px; background-color: darkorange; color: white; font-size: 18px; cursor: pointer; margin: 20px" onclick="sendEmailFP()">Tìm</span>
        </div>
    </div>
    <div class="col-lg-4 col-xs-12"></div>
</div>
</div>
</body>

<script>
    $(document).ready(function(){
        $(document).bind('keypress', function(e) {
            if(e.keyCode==13){
                sendEmailFP();
            }
        });
    });

    function sendEmailFP(){
        $('#divReSendEmailFP').html('');
        var url = "<?php echo base_url() ?>";
        var email = $('#txtReSendEmailFP').val();
        var captcha = $('#txtReSendCaptchaFP').val();
        if(email == ''){
            $('#divReSendEmailFP').html("<span style='color: red'>Xin vui lòng nhập địa chỉ email để thực hiện tìm kiếm!</span>");
        }
        else{
            if(captcha == ''){
                $('#divReSendEmailFP').html("<span style='color: red'>Xin vui lòng nhập đoạn mã bên trên!</span>");
            }
            else{
                var dataString = "email="+email+"&captcha="+captcha;
//        alert(dataString);
                $.ajax({
                    type: "POST",
                    url: url+'users/checkEmailFP',
                    data: dataString,
                    success: function(x){
//                alert(x);
                        if(x == 2){
                            $('#txtReSendCaptchaFP').val('');
                            $('#divReSendEmailFP').html("<span style='color: red'>Mã bảo mật không đúng!</span>");
                            $('#btnChangeCaptcha').click();
                        }
                        else if(x == 1){
                            window.location.href = "<?php echo base_url() ?>password/reset?email="+email;
                        }
                        else{
                            $('#divReSendEmailFP').html("<span style='color: red'>Đã xảy ra lỗi. Xin vui lòng kiểm tra lại email và thử lại!</span>");
                        }
                    }
                });
            }
        }
    }
</script>

<script>
    function changeCaptcha(){
        $('#txtReSendCaptchaFP').val('');
        var url = "<?php echo base_url() ?>";
        $.ajax({
            url: url+"users/getCaptcha/1",
            success: function(x){
//                alert(x);
                $('#imgCaptcha').html(x);
            }
        });
    }
</script>